package SteamEngineFX.util;

//import java.text.DateFormat;
//import java.text.MessageFormat;
//import java.text.SimpleDateFormat;
//import java.util.Date;
//import java.util.TimeZone;
import java.util.Date;
import org.joda.time.DateTime;
import org.joda.time.LocalTime;

/**
 *
 * @author jbendixsen
 */
public final class RunTime {
    
    private LocalTime runTime;
        
    public RunTime(int hour, int minute){
        //For train runs we only care about hours and minutes
        runTime = new LocalTime(hour, minute);
    }
    
    public RunTime(Date date){
        DateTime dt = new DateTime(date);
        runTime = new LocalTime(dt.toLocalTime().getHourOfDay(), dt.toLocalTime().getMinuteOfHour());
    }
    
    public Date getDate(){
        DateTime dt = new DateTime();
        return runTime.toDateTime(dt).toDate();
    }
    
    public String toString(){

        String h = "00";
        if (runTime.getHourOfDay() > 9){
            h = Integer.toString(runTime.getHourOfDay());
        }else if(runTime.getHourOfDay() > 0){
            h = "0" + Integer.toString(runTime.getHourOfDay());
        }
        
        String m = "00";
        if (runTime.getMinuteOfHour() > 9){
            m = Integer.toString(runTime.getMinuteOfHour());
        }else if(runTime.getMinuteOfHour() > 0){
            m = "0" + Integer.toString(runTime.getMinuteOfHour());
        }
        
        return String.format("%s:%s", h, m);
    }
}
